//
//  AppDelegate.m
//  BookSale
//
//  Created by dlios on 15-3-9.
//  Copyright (c) 2015年 dlios. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate
-(void)dealloc
{
    [_window release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    //首页
    RootViewController *rootVC = [[RootViewController alloc] init];
    
    UINavigationController *rootNAVC = [[UINavigationController alloc] initWithRootViewController:rootVC];
    rootNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"首页" image:[UIImage imageNamed:@"iconfont-shouye.png"] tag:1001];
    
    //分类
    TypeViewController *typeVC = [[TypeViewController alloc] init];
    UINavigationController *typeNAVC = [[UINavigationController alloc] initWithRootViewController:typeVC];
    typeNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"分类" image:[UIImage imageNamed:@"iconfont-fenlei.png"] tag:1002];
    
    
    //搜索
    SearchViewController *searchVC = [[SearchViewController alloc] init];
    UINavigationController *searchNAVC = [[UINavigationController alloc] initWithRootViewController:searchVC];
    searchNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"搜索" image:[UIImage imageNamed:@"iconfont-sousuo.png"] tag:1003];
    
    //书架
    BookShelfViewController *bookShelfVC = [[BookShelfViewController alloc] init];
    UINavigationController *bookShelfNAVC = [[UINavigationController alloc] initWithRootViewController:bookShelfVC];
    //设置图片不被渲染
    //    UIImage *bookShelfImage = [UIImage imageNamed:@"iconfont-shujia-2.png"];
    //    bookShelfImage = [bookShelfImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    bookShelfNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"书架" image:[UIImage imageNamed:@"iconfont-shujia-2.png"] tag:1004];
    
    //创建tabbar
    UITabBarController *tabBarController = [[UITabBarController alloc] init];
    tabBarController.viewControllers = [NSArray arrayWithObjects:rootNAVC, typeNAVC, searchNAVC, bookShelfNAVC, nil];
    tabBarController.tabBar.translucent = NO;
    
    //导航栏为不透明
    rootNAVC.navigationBar.translucent = NO;
    typeNAVC.navigationBar.translucent = NO;
    searchNAVC.navigationBar.translucent = NO;
    bookShelfNAVC.navigationBar.translucent = NO;
    //指定window的根视图为tabBarController
    self.window.rootViewController = tabBarController;
    //    //设置背景图片
    //    tabBarController.tabBar.backgroundImage = [UIImage imageNamed:@"navbar2.png"];
    
    //设置tabbar的背景颜色
    tabBarController.tabBar.barTintColor = [UIColor colorWithRed:63/255.0 green:23/255.0 blue:8/255.0 alpha:0];
    tabBarController.tabBar.tintColor = [UIColor blackColor];
    
    
    //设置UINavigationBar的背景图片
    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbar2.png"] forBarPosition:UIBarPositionTopAttached barMetrics:UIBarMetricsDefault];
    [tabBarController release];
    
    [rootVC release];
    [rootNAVC release];
    
    [typeVC release];
    [typeNAVC release];
    
    [searchVC release];
    [searchNAVC release];
    
    [bookShelfVC release];
    [bookShelfNAVC release];

    
    //友盟
    [UMSocialData setAppKey:@"507fcab25270157b37000010"];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
